package siau.android.base

import android.content.Context
import android.util.TypedValue
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import hhm.android.library.utils.GetIntListener
import hhm.android.library.utils.GetStringListener
import hhm.android.library.utils.OnMultiClickListener

class BottomShareFriendsSheet : BottomSheetDialog {

    private var listener: GetIntListener

    constructor(context: Context, listener: GetIntListener) : super(context) {
        createView()
        this.listener = listener
    }

    fun createView() {
        val bottomSheetView: View = layoutInflater.inflate(R.layout.item_bottom_share_friends, null)
        setContentView(bottomSheetView)

        bottomSheetView.findViewById<LinearLayout>(R.id.item_bottom_share_friends_wechat_friends_ll).setOnClickListener(object : OnMultiClickListener() {
            override fun onMultiClick(v: View?) {
                listener.getInt(0)
                dismiss()
            }
        })

        bottomSheetView.findViewById<LinearLayout>(R.id.item_bottom_share_friends_wechat_ll).setOnClickListener(object : OnMultiClickListener() {
            override fun onMultiClick(v: View?) {
                listener.getInt(1)
                dismiss()
            }
        })

        bottomSheetView.findViewById<TextView>(R.id.item_bottom_share_friends_cancel).setOnClickListener(object : OnMultiClickListener() {
            override fun onMultiClick(v: View?) {
                dismiss()
            }
        })


        // 注意：这里要给layout的parent设置peekHeight，而不是在layout里给layout本身设置，下面设置背景色同理，坑爹！！！
        val bottomSheetBehavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(
            bottomSheetView.parent as View
        )
//        bottomSheetBehavior.peekHeight = dp2px(235f)
        //允许点击外部关闭，不允许滑动关闭
        bottomSheetBehavior.isHideable = false
        (bottomSheetView.parent as View).setBackgroundColor(context.resources.getColor(R.color.trans))
    }

    fun dp2px(dpValue: Float?): Int {
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, dpValue!!, context.resources.displayMetrics
        ).toInt()
    }
}